package com.three.digit.group;

import java.util.ArrayList;
import java.util.List;

import com.three.digit.model.Point;

public class NearNumbersGroup extends BasicGroup
{

    public NearNumbersGroup (boolean useBasicData)
    {
        super (useBasicData);
    }

    public String[] hashKey (Point point)
    {
        List <String> key = new ArrayList <String> ();

        List <Integer> xAxis = calcHash (point.getX ());
        List <Integer> yAxis = calcHash (point.getY ());
        List <Integer> zAxis = calcHash (point.getZ ());

        for (int i = 0; i < xAxis.size (); i++)
        {
            for (int j = 0; j < yAxis.size (); j++)
            {
                for (int z = 0; z < zAxis.size (); z++)
                {
                    key.add (xAxis.get (i) + "" + yAxis.get (j) + "" + zAxis.get (z));
                }
            }
        }

        return key.toArray (new String[key.size ()]);
    }

    private List <Integer> calcHash (int num)
    {
        List <Integer> hash = new ArrayList <Integer> ();

        hash.add (num);

        if (num - 1 >= 0)
        {
            hash.add (num - 1);
        }

        if (num + 1 <= 9)
        {
            hash.add (num + 1);
        }

        return hash;
    }
}
